<?php
namespace App\Http\Controllers\App;

use App\Http\Controllers\Controller;
use App\Company;
use Illuminate\Http\Request;

class CompanyController extends Controller{

    /**
     * @return Company
     */
    protected function getCompany()
    {
        $user = \Auth::user();
        $company = $user->company;
        return $company;
    }

    public function show()
    {
        return view('company.show',[
            'company'=>$this->getCompany()
        ]);
    }

    public function edit()
    {
        return view('company.edit',[
            'company'=>$this->getCompany()
        ]);
    }

    public function update(Request $request)
    {
        $company = $this->getCompany();
        $company->fill($request->post());
        $file = $request->file('file');
        if($file&&$filename = $file->store('/public')){
            $company->license_business_pic = last(explode('/',$filename));
        }

        $company->save();
        return redirect()->route('company.show');
    }
}